import Vue from 'vue';
import VueRouter from 'vue-router';
import { databaseui_router } from '@/router/databaseui.router';
import { apimanager_router } from '@/router/apimanager.router';

Vue.use(VueRouter);

const routes = [
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/Home/index.vue'),
  },
  {
    path: '/routerhelp',
    name: 'routerhelp',
    component: () => import('@/views/routerhelp/routerhelp.vue'),
  },
  {
    path: '/ngnixmanange',
    name: 'ngnixmanange',
    component: () => import('@/views/ngnixmanange/index.vue'),
  },
  ...databaseui_router,
  ...apimanager_router,
  {
    path: '/codegerenate1',
    name: 'codegerenate1',
    component: () => import('@/views/manage/codegerenate1/index.vue'),
  },
  {
    path: '/systemgenerete',
    name: 'systemgenerete',
    component: () => import('@/views/manage/codegerenate1/systemgenerete.vue'),
  },
  
  {
    path: '/swagger1',
    name: 'swagger1',
    component: () => import('@/views/manage/swagger1/index.vue'),
  },
  
  {
    path: '/',
    redirect: '/home',
  },
];


function getComponent() {
  return import.meta.glob('../views/manage/**/*.vue', { eager: true });
}

// 获取路由文件
export const fillVueRouters = (_routerList = []) => {
  const files = getComponent();
  Object.keys(files).forEach((fileSrc) => {
    const component = files[fileSrc];
    const componentPath = fileSrc.replace(/^\.\//, '');
    const routerPath = componentPath.replace('../views', '').replace(/\/index.ts$/, '').replace(/.vue$/, '');
    if (!componentPath.includes('components')) {
      console.log("=>[routerPath]", routerPath);
      
      _routerList.push({
        path: routerPath,
        name: component?.default?.name,
        component: () => import(/* @vite-ignore */componentPath),
        meta: {
          title: component?.default?.title,
          // skeleton: component.skeleton, // TODO 待处理页面骨架屏
          // background: component.backgroundColor, // TODO 待处理页面级别颜色
        },
      });
      
    }
  });
  return _routerList;
};

fillVueRouters(routes);

const router = new VueRouter({
  mode: 'history',
  base: '/supplier',
  routes,
});

export default router;
